package com.kebo2.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootLayoutPanel;

public class Kebo2 implements EntryPoint {

	public void onModuleLoad() {
		
		final String userAgent = Window.Navigator.getUserAgent();
		if(userAgent.contains("MSIE6") || userAgent.contains("MSIE7") || userAgent.contains("MSIE8")) {
			upgradeBrowser();
			return;
		}
		
		HttpRequest object = new HttpRequest();
		object.getMessageXml("checkLogin.php", "GET", "null", new AsyncCallback<String>() {
			public void onSuccess(String result) {
				int r = Integer.parseInt(result);
				if(r == 0) 
					new UIBeforeLogin();
				else if(r == 1) 
					new UIAfterLogin();
				else if(r == 2) 
					new Update();
				else 
					RootLayoutPanel.get().add(new HTML("There went something wrong with loading the UI. Pleas contact your webmaster."));
			}
			public void onFailure(Throwable caught) {
				new UserInterface.notification(Kebo2.error.INTERNET_CONNECTION);
			}
		});	
	}

	private void upgradeBrowser() {
		// TODO Auto-generated method stub
		
	}
	
	public static class error {
		public final static String INTERNET_CONNECTION = "Er ging iets fout. Kijk aub uw internetverbinding na.";
		public final static String XML_PARSE = "Kon het XML document niet lezen.";
	}
}
